/*
* FilePremier Chrome Plugin
*/

var viperfx = {
 regexpute: [],
 autodownload: -1,
 popupPos: 1,
 autoreconnect: false,
 username: "",
 password: "",
 showpopup: true,

getItem: function (key) {
    var value;
    try {
        value = window.localStorage.getItem(key);
    }catch(e) {
        value = "null";
    }
    return value;
},

setItem: function(key, value) {
    try {
        window.localStorage.removeItem(key);
        window.localStorage.setItem(key, value);
    }catch(e) {
    }
},

loadLocalSettings: function() {
    viperfx.servDeb = viperfx.getItem("servdeb");
    if(!viperfx.servDeb){
        viperfx.setItem("servdeb","1");
        viperfx.servDeb = "1";
        viperfx.setItem("autodownload","-1");
        viperfx.setItem("popuppos","1");
        viperfx.setItem("autoreconnect","false");
        viperfx.setItem("username","");
        viperfx.setItem("password","");
        viperfx.setItem("showpopup","true");
    }

    viperfx.autodownload   = parseInt(viperfx.getItem("autodownload"));
    viperfx.popupPos       = (viperfx.getItem("popuppos") == 1) ? "popItRight" : "popItLeft";
    viperfx.autoreconnect  = (viperfx.getItem("autoreconnect") == "true");
    viperfx.username       = viperfx.getItem("username");
    viperfx.password       = viperfx.getItem("password");
    viperfx.showpopup      = (viperfx.getItem("showpopup") == "true");
},

fileDebridLoad: function() {

    viperfx.loadLocalSettings();
	
	viperfx.regexpute = new Array(
   /http:\/\/(\w+\.)?megaupload\.com\/([a-zA-Z]+\/)?\?[a-zA-Z]=[0-9a-zA-Z]{8}/g,
    /(http|https):\/\/(\w+\.)?rapidshare\.com\/(files\/[0-9]+\/[0-9a-zA-Z\.-_]+|#!d)[^( |"|>|<|\r\n\|\n|$)]+/g,
    /(http|https):\/\/rs[a-z0-9]+.rapidshare\.com\/(files\/[^( |"|>|<|\r\n\|\n|$)]+|#!download[^( |"|>|<|\r\n\|\n|$)]+)/g,
    /http:\/\/(\w+\.)?megavideo\.com\/([a-zA-Z]+\/)?\?[a-zA-Z]=[0-9a-zA-Z]{8}/g,
    /http:\/\/(\w+\.)?netload\.in\/[0-9a-zA-Z]+\/?(.*)?\.htm/g,
    /http:\/\/(\w+\.)?fileserve\.com\/file\/[^\"\r\n< ]+/g,
    /http:\/\/(\w+\.)?hotfile\.com\/dl\/[0-9a-zA-Z]+\/[\/[0-9a-zA-Z]+\//g,
	 /http:\/\/(www\.)?uploadstation\.com\/file\/[^( |"|>)]+/g,
    /http:\/\/(\w+\.)?(sharingmatrix|filesonic)\.(com|fr|de|it|net|org|jp)\/file\/[^\"\r\n< ]+/g,
    /http:\/\/(\w+\.)?(wupload)\.(com|fr|de|it|net|org|jp)\/file\/[^\"\r\n< ]+/g,
    /http:\/\/(www\.)?fileserve\.com\/list\/[^( |"|>)]+/g,
    /http:\/\/(\w+\.)?(wupload)\.(com|fr|de|it|net|org|jp)\/folder\/[^\"\r\n< ]+/g,
    /http:\/\/(\w+\.)?netfolder\.in\/(folder\.php\?folder_id\=(\w+)|([0-9a-zA-Z]+)\/[0-9]+)/g,
    /http:\/\/(www\.)?hotfile\.com\/list\/[^( |"|>)]+/g,
    /http:\/\/(www\.)?uploadstation\.com\/list\/[^( |"|>)]+/g,
    /http:\/\/(www\.)?filesonic\.(com|it|de|es|fr|hk|jp)\/folder\/[^( |"|>)]+/g,
    /http:\/\/(\w+\.)?uploading\.com\/files\/[0-9A-Za-z]+\/?(.*)?/g,
    /http:\/\/(\w+\.)?linksave\.in\/([0-9a-zA-Z]+)/g
    );

chrome.pageAction.onClicked.addListener(function(tab) { chrome.tabs.executeScript(viperfx.activeId,{code:"popItUp()",allFrames:false}); });

},

fileDebridCheckLink: function(link) {
    if(!link) return 0;
    var i;
    for(i=0;i<viperfx.regexpute.length;i++) {
            var res = link.match(viperfx.regexpute[i]);

            if(res) {
                return true;
            }
    }
    return 0;
},

folderCheckLink: function(link) {
	var folder = new Array(
		/http:\/\/(www\.)?megaupload\.com(\/[a-z]{2})?\/\?f=[0-9a-zA-Z]+/g,
		/http:\/\/(\w+\.)?netfolder\.in\/(folder\.php\?folder_id\=(\w+)|([0-9a-zA-Z]+)\/[0-9]+)/g,
		/http:\/\/(www\.)?hotfile\.com\/list\/[^( |"|>)]+/g,
		 /http:\/\/(www\.)?uploadstation\.com\/list\/[^( |"|>)]+/g,
		 /http:\/\/(www\.)?filesonic\.(com|it|de|es|fr|hk|jp)\/folder\/[^( |"|>)]+/g,
		/http:\/\/(\w+\.)?(wupload)\.(com|fr|de|it|net|org|jp)\/folder\/[^\"\r\n< ]+/g,
		/http:\/\/(www\.)?fileserve\.com\/list\/[^( |"|>)]+/g,
		/http:\/\/(\w+\.)?linksave\.in\/([0-9a-zA-Z]+)/g
		);
	
    if(!link) return 0;
    var i;    
    for(i=0;i<folder.length;i++) {
		var res = link.match(folder[i]);
		if(res) return res;
		}    return 0;
}
}
